package com.zhanghu.backendZray.converter;

import com.zhanghu.backendZray.pojo.entity.User;
import com.zhanghu.backendZray.pojo.request.user.UserRequest;
import com.zhanghu.backendZray.pojo.vo.UserVo;
import org.springframework.stereotype.Component;

/**
 * @author ZhangDong
 * @date 2024/7/25 20:34
 */
@Component
public class UserConverter extends Converter<UserRequest, User, UserVo> {
    protected UserConverter() {
        super(UserConverter::request2user, UserConverter::user2Vo);
    }

    private static User request2user(UserRequest input) {
        User user = new User();
        user.setId(input.getId());
        user.setName(input.getName());
        user.setPhone(input.getPhone());
        user.setPassword(input.getPassword());
        return user;
    }

    private static UserVo user2Vo(User user) {
        UserVo userVo = new UserVo();
        userVo.setId(user.getId());
        userVo.setName(user.getName());
        userVo.setPhone(user.getPhone());
        userVo.setWxNickName(user.getWxNickName());
        userVo.setWxAvatar(user.getWxAvatar());
        return userVo;
    }
}
